﻿Imports PostSharp.Aspects
Imports System.Transactions

<Serializable(), AttributeUsage(AttributeTargets.Method)> _
Public Class RollingBackTransaction
	Inherits OnMethodBoundaryAspect

    Public Overrides Sub OnEntry(ByVal eventArgs As PostSharp.Aspects.MethodExecutionArgs)
        Dim scope As TransactionScope

        scope = New TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(12))
        eventArgs.MethodExecutionTag = scope

    End Sub

    Public Overrides Sub OnExit(ByVal eventArgs As PostSharp.Aspects.MethodExecutionArgs)
        Dim scope As TransactionScope

        scope = CType(eventArgs.MethodExecutionTag, TransactionScope)
        If (Not scope Is Nothing) Then
            scope.Dispose()
        End If

    End Sub

End Class
